from django.db import models
# from tinymce.models import HTMLField
from DjangoUeditor.models import UEditorField


# Create your models here.

class UserData(models.Model):
    name = models.CharField(max_length=50)
    tel = models.IntegerField()
    text = models.TextField(null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = '用户登记'


class ClickTimes(models.Model):
    times = models.IntegerField(default=0)

    def __str__(self):
        return str(self.times)

    class Meta:
        verbose_name_plural = '点击次数'


class ProjectClass(models.Model):
    name = models.CharField(max_length=20)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = '项目分类'


class Projects(models.Model):
    title = models.CharField(max_length=20)
    pic = models.ImageField(upload_to='web_pic')
    belong_class = models.ForeignKey(to=ProjectClass, related_name='all_pro', on_delete=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = '项目列表'


class Languages(models.Model):
    language = models.CharField(max_length=20)

    def __str__(self):
        return self.language

    class Meta:
        verbose_name_plural = '语言'


class Databases(models.Model):
    database = models.CharField(max_length=20)

    def __str__(self):
        return self.database

    class Meta:
        verbose_name_plural = '数据库'


class ProjectDetail(models.Model):
    name = models.CharField(max_length=40)
    belong_pro = models.OneToOneField(to=Projects, on_delete=True)
    belong_language = models.ForeignKey(to=Languages, on_delete=True)
    belong_database = models.ForeignKey(to=Databases, on_delete=True)
    content = UEditorField(u'内容	',width=800, height=300, toolbars="full",
                           imagePath="content_images/%(basename)s_%(datetime)s.%(extname)s",
                           filePath="content_files/%(basename)s_%(datetime)s.%(extname)s",
                           upload_settings={"imageMaxSize":1204000}, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = '项目详情'


class ConnectionUs(models.Model):
    web_posi = models.CharField(max_length=20)
    e_mail = models.EmailField()
    tel = models.CharField(max_length=11)
    address = models.CharField(max_length=50)

    def __str__(self):
        return self.address

    class Meta:
        verbose_name_plural = '联系我们'
